home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Devices and Hardware / ADB / ControlKeyPatch / ControlKeyPatch.a.c next >
Encoding:
Text File  |  2000-09-28  |  2.7 KB  |  116 lines  |  [TEXT/MPS ]

  1. /*    File:        ControlKeyPatch.a.c
  2.     
  3.     Description: 
  4.              routines for patching the ADB manager to simulate the control
  5.             key being held down.  This file contains the 68000 code for
  6.             the patch resource.  It is identical to the file ControlKeyPatch.a
  7.             except it is reformatted for use with CodeWarrior.
  8.  
  9.     Author:    John Montbriand
  10.  
  11.     Copyright: 
  12.             Copyright © 1999 by Apple Computer, Inc.
  13.             All rights reserved worldwide.
  14.     
  15.     Disclaimer:
  16.             You may incorporate this sample code into your applications without
  17.             restriction, though the sample code has been provided "AS IS" and the
  18.             responsibility for its operation is 100% yours.  However, what you are
  19.             not permitted to do is to redistribute the source as "DSC Sample Code"
  20.             after having made changes. If you're going to re-distribute the source,
  21.             we require that you make it clear in the source that the code was
  22.             descended from Apple Sample Code, but that you've made changes.
  23.     
  24.     Change History (most recent first):
  25.             27/8/99 created by John Montbriand
  26. */
  27.  
  28. enum {
  29.     command = 0, /*  key down command */
  30.     downflag = 4, /* flag for tracking key */
  31.     originaljump = 8, /* original service routine */
  32.     originaldata = 12 /* original service routine's data */
  33. };
  34.  
  35. asm void __Startup__(void) {
  36.  
  37.     bra.s    ADBPatch
  38.     bra.s    SetDown
  39.     bra.s    SetUp
  40.  
  41.  
  42. controldown: dc.l        0x0236FF00
  43.     
  44. controlup: dc.l        0x02B6FF00
  45.  
  46. SetDown:
  47.     movea.l        4(SP), A2
  48.     cmpi.l        #1, downflag(A2)    // test to see if the key is already down
  49.     beq.s        SetDownExit
  50.             // set the down flag to true
  51.         move.l        #1, downflag(A2)
  52.             // jump to the original service routine
  53.         move.l        command(A2), D0
  54.         lea        controldown, A0
  55.         movea.l        #0, A1
  56.         move.l        originaljump(A2), -(SP)
  57.         movea.l        originaldata(A2), A2
  58.         rts
  59.         
  60.     SetDownExit:
  61.     rts
  62.  
  63. SetUp:
  64.     movea.l        4(SP), A2
  65.     cmpi.l        #0, downflag(A2)    // test to see if the key is already up
  66.     beq.s        SetUpExit
  67.             // set the down flag to false
  68.         move.l        #0, downflag(A2)
  69.             // jump to the original service routine
  70.         move.l        command(A2), D0
  71.         lea        controlup, A0
  72.         movea.l        #0, A1
  73.         move.l        originaljump(A2), -(SP)
  74.         movea.l        originaldata(A2), A2
  75.         rts
  76.         
  77.     SetUpExit:
  78.     rts
  79.  
  80. ADBPatch:
  81.         // R0?
  82.     btst            #0, D0
  83.     bne.s        @1
  84.     btst            #1, D0
  85.     bne.s        @1
  86.         // talk?
  87.     btst            #2, D0
  88.     beq.s        @1
  89.     btst            #3, D0
  90.     beq.s        @1
  91.         // test to see if the key is locked down
  92.     cmpi.l        #1, downflag(A2)    // test to see if the key is down
  93.     bne.s        @1
  94.             // block key downs
  95.         cmpi.b        #0x02, 0(A0)
  96.         bne.s        @2
  97.         cmpi.b        #0x36, 1(A0)
  98.         bne.s        @2
  99.         cmpi.b        #0xFF, 2(A0)
  100.         bne.s        @2
  101.             rts
  102.         @2:    // block key ups
  103.         cmpi.b        #0x02, 0(A0)
  104.         bne.s        @1
  105.         cmpi.b        #0xB6, 1(A0)
  106.         bne.s        @1
  107.         cmpi.b        #0xFF, 2(A0)
  108.         bne.s        @1
  109.             rts
  110.     @1:    // jump through to the original routine
  111.     move.l        originaljump(A2), -(SP)
  112.     movea.l        originaldata(A2), A2
  113.     rts
  114.     
  115. }
  116.